//
//  YBLoginCreateZjcViewController.m
//  Nectar
//
//  Created by famer on 2023/11/7.
//  Copyright © 2023 asance. All rights reserved.
//

#import "YBLoginCreateZjcViewController+LayoutConstraints.h"
#import "YBLoginVerifyZjcViewController.h"
#import "YBNextStepView.h"
#import "YBNavigationBar.h"

@interface YBLoginCreateZjcViewController ()

@end

@implementation YBLoginCreateZjcViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setCleanEdgesForExtendedLayout];
    
//    [self.view addSubview:self.navigationBar];
    [self.view addSubview:self.createWalletLabel];
    [self.view addSubview:self.backupWalletImageView];
    [self.view addSubview:self.backupWalletLabel];
    
    [self.view addSubview:self.zjcContentView];
    [self initZjcItemView];

    [self.zjcContentView addSubview:self.verLineView1];
    [self.zjcContentView addSubview:self.verLineView2];
    [self.zjcContentView addSubview:self.horLineView1];
    [self.zjcContentView addSubview:self.horLineView2];
    [self.zjcContentView addSubview:self.horLineView3];
    
    [self.view addSubview:self.nextStepView];
    
    [self.view addSubview:self.dotView1];
    [self.view addSubview:self.dotLabel1];
    [self.view addSubview:self.dotView2];
    [self.view addSubview:self.dotLabel2];
    
    [self.nextStepView setNextStepButtonEnabled];
    [self setLayoutConstraints];
}

#pragma mark - Private Method
- (void)initZjcItemView{
    _zjcItemLabelArray = [[NSMutableArray alloc] init];
//    [self.nodeArray makeObjectsPerformSelector:@selector(removeFromSuperview)];
    _zjcIndexLabelArray = [[NSMutableArray alloc] init];

    NSArray *components = [self.zjc componentsSeparatedByString:@","];
    for (int i=0; i<[components count]; i++) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
        label.font = [UIFont systemFontOfSize:14];
        label.text = [components objectAtIndex:i];
        label.textColor = [UIColor hexColor:@"1E1E1E"];
        label.textAlignment = NSTextAlignmentCenter;
        label.numberOfLines = 0;
        label.lineBreakMode = NSLineBreakByWordWrapping;
        [self.zjcContentView addSubview:label];
        [_zjcItemLabelArray addObject:label];
        
        UILabel *indexLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        indexLabel.font = [UIFont systemFontOfSize:10];
        indexLabel.text = [NSString stringWithFormat:@"%@",@(i+1)];
        indexLabel.textColor = [UIColor hexColor:@"9AA0A5"];
        indexLabel.textAlignment = NSTextAlignmentCenter;
        indexLabel.numberOfLines = 0;
        indexLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [label addSubview:indexLabel];
        [_zjcIndexLabelArray addObject:indexLabel];
    }
}

- (void)doVerify{
    YBLoginVerifyZjcViewController *viewcontroller = [[YBLoginVerifyZjcViewController alloc] init];
    viewcontroller.email = self.email;
    viewcontroller.password = self.password;
    viewcontroller.zjc = self.zjc;
    viewcontroller.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:viewcontroller animated:YES];
}

#pragma mark - Getter Setter
YBLabelGetter(createWalletLabel, _createWalletLabel, [UIFont boldSystemFontOfSize:20], @"Create Wallet", [UIColor hexColor:@"1E1E1E"], NSTextAlignmentLeft);

YBImageViewGetter(backupWalletImageView, _backupWalletImageView, [UIImage imageNamed:@"icon_create_wallet_verify"]);
YBLabelGetter(backupWalletLabel, _backupWalletLabel, [UIFont systemFontOfSize:16], @"Backup Mnemonic Phrase", [UIColor hexColor:@"1E1E1E"], NSTextAlignmentLeft);

YBViewGetter(zjcContentView, _zjcContentView, [UIColor hexColor:@"FBFCFE"])
YBViewGetter(verLineView1, _verLineView1, [UIColor hexColor:@"F6F5F6"])
YBViewGetter(verLineView2, _verLineView2, [UIColor hexColor:@"F6F5F6"])
YBViewGetter(horLineView1, _horLineView1, [UIColor hexColor:@"F6F5F6"])
YBViewGetter(horLineView2, _horLineView2, [UIColor hexColor:@"F6F5F6"])
YBViewGetter(horLineView3, _horLineView3, [UIColor hexColor:@"F6F5F6"])

YBViewGetter(dotView1, _dotView1, [UIColor hexColor:@"84828C"])
YBViewGetter(dotView2, _dotView2, [UIColor hexColor:@"84828C"])
YBLabelGetter(dotLabel1, _dotLabel1, [UIFont systemFontOfSize:12], @"Please keep the mnemonic phrase safe, raw wallet cannot retrieve it for you.", [UIColor hexColor:@"84828C"], NSTextAlignmentLeft);
YBLabelGetter(dotLabel2, _dotLabel2, [UIFont systemFontOfSize:12], @"Please try to keep it offline and do not save and transmit it through email, chat software, or online documents.", [UIColor hexColor:@"84828C"], NSTextAlignmentLeft);


- (YBNavigationBar *)navigationBar{
    if(!_navigationBar){
        _navigationBar = [[YBNavigationBar alloc] initWithFrame:CGRectZero];
        [_navigationBar setTitle:kLogin titleColor:[UIColor blackColor]];
        [_navigationBar setRightBarTitle:@"" forState:UIControlStateNormal];
        [_navigationBar setRightBarTitleColor:[UIColor hexColor:@"0099ff"] forState:UIControlStateNormal];
        __weak __typeof(&*self)weakSelf = self;
        _navigationBar.onLeftBarButtonBlock = ^(){
            __strong __typeof(&*weakSelf)strongSelf = weakSelf;
            if(!strongSelf) return;
            
            [strongSelf.navigationController dismissViewControllerAnimated:YES completion:nil];
        };
        _navigationBar.onRightBarButtonBlock = ^(){
            __strong __typeof(&*weakSelf)strongSelf = weakSelf;
            if(!strongSelf) return;
            [strongSelf.navigationController popViewControllerAnimated:YES];
        };
    }
    return _navigationBar;
}

- (YBNextStepView *)nextStepView{
    if(!_nextStepView){
        _nextStepView = [[YBNextStepView alloc] initWithFrame:CGRectZero];
        [_nextStepView setButtonTitle:kBtnNext];
        [_nextStepView setNextStepButtonUnabled];
        __weak __typeof(&*self)weakSelf = self;
        _nextStepView.onNextStepBlock = ^{
            __strong __typeof(&*weakSelf)strongSelf = weakSelf;
            if(!strongSelf) return;
            
            //去验证
            [strongSelf doVerify];
        };
    }
    return _nextStepView;
}
@end
